import { reactive } from "vue";
import type { FormRules } from "element-plus";

interface FormItemProps {
  id?: string;
  title: string;
  description: string;
  category: string;
  instructorId: number;
  instructorName: string;
  maxStudents: number;
  currentStudents: number;
  price: number;
  originalPrice: number;
  startTime: string;
  endTime: string;
  duration: number;
  location: string;
  address: string;
  status: TrainingStatus;
  level: TrainingLevel;
  tags: string;
  coverImage: string;
  content: string;
  requirements: string;
  objectives: string;
  schedule: string;
  materials: string;
  certificate: boolean;
  remark: string;
  createTime?: string;
  updateTime?: string;
}

interface FormProps {
  formInline: FormItemProps;
}

/** 培训状态枚举 */
enum TrainingStatus {
  DRAFT = 0,      // 草稿
  PUBLISHED = 1,  // 已发布
  ONGOING = 2,    // 进行中
  COMPLETED = 3,  // 已完成
  CANCELLED = 4   // 已取消
}

/** 培训级别枚举 */
enum TrainingLevel {
  BEGINNER = 1,     // 初级
  INTERMEDIATE = 2, // 中级
  ADVANCED = 3,     // 高级
  EXPERT = 4        // 专家级
}

/** 培训状态文本映射 */
const TrainingStatusText = {
  [TrainingStatus.DRAFT]: "草稿",
  [TrainingStatus.PUBLISHED]: "已发布",
  [TrainingStatus.ONGOING]: "进行中",
  [TrainingStatus.COMPLETED]: "已完成",
  [TrainingStatus.CANCELLED]: "已取消"
};

/** 培训级别文本映射 */
const TrainingLevelText = {
  [TrainingLevel.BEGINNER]: "初级",
  [TrainingLevel.INTERMEDIATE]: "中级",
  [TrainingLevel.ADVANCED]: "高级",
  [TrainingLevel.EXPERT]: "专家级"
};

/** 培训分类选项 */
const TrainingCategoryOptions = [
  { label: "羽毛球培训", value: "badminton" },
  { label: "乒乓球培训", value: "table-tennis" },
  { label: "网球培训", value: "tennis" },
  { label: "篮球培训", value: "basketball" },
  { label: "足球培训", value: "football" },
  { label: "游泳培训", value: "swimming" },
  { label: "健身培训", value: "fitness" },
  { label: "瑜伽培训", value: "yoga" },
  { label: "其他培训", value: "other" }
];

/** 表单验证规则 */
const formRules = reactive(<FormRules>{
  title: [
    { required: true, message: "培训标题为必填项", trigger: "blur" },
    {
      min: 2,
      max: 50,
      message: "培训标题长度应为2-50个字符",
      trigger: "blur"
    }
  ],
  description: [
    { required: true, message: "培训描述为必填项", trigger: "blur" },
    {
      min: 10,
      max: 200,
      message: "培训描述长度应为10-200个字符",
      trigger: "blur"
    }
  ],
  category: [
    { required: true, message: "请选择培训分类", trigger: "change" }
  ],
  instructorName: [
    { required: true, message: "讲师姓名为必填项", trigger: "blur" },
    {
      min: 2,
      max: 20,
      message: "讲师姓名长度应为2-20个字符",
      trigger: "blur"
    }
  ],
  maxStudents: [
    { required: true, message: "最大学员数为必填项", trigger: "blur" },
    {
      type: "number",
      min: 1,
      max: 1000,
      message: "最大学员数应为1-1000之间的数字",
      trigger: "blur"
    }
  ],
  price: [
    { required: true, message: "培训价格为必填项", trigger: "blur" },
    {
      type: "number",
      min: 0,
      message: "培训价格不能小于0",
      trigger: "blur"
    }
  ],
  originalPrice: [
    {
      type: "number",
      min: 0,
      message: "原价不能小于0",
      trigger: "blur"
    }
  ],
  startTime: [
    { required: true, message: "请选择开始时间", trigger: "change" }
  ],
  endTime: [
    { required: true, message: "请选择结束时间", trigger: "change" }
  ],
  duration: [
    { required: true, message: "培训时长为必填项", trigger: "blur" },
    {
      type: "number",
      min: 1,
      message: "培训时长必须大于0",
      trigger: "blur"
    }
  ],
  location: [
    { required: true, message: "培训地点为必填项", trigger: "blur" },
    {
      min: 2,
      max: 50,
      message: "培训地点长度应为2-50个字符",
      trigger: "blur"
    }
  ],
  address: [
    { required: true, message: "详细地址为必填项", trigger: "blur" },
    {
      min: 5,
      max: 100,
      message: "详细地址长度应为5-100个字符",
      trigger: "blur"
    }
  ],
  status: [
    { required: true, message: "请选择培训状态", trigger: "change" }
  ],
  level: [
    { required: true, message: "请选择培训级别", trigger: "change" }
  ],
  content: [
    { required: true, message: "培训内容为必填项", trigger: "blur" },
    {
      min: 20,
      max: 2000,
      message: "培训内容长度应为20-2000个字符",
      trigger: "blur"
    }
  ],
  requirements: [
    {
      max: 500,
      message: "报名要求不能超过500个字符",
      trigger: "blur"
    }
  ],
  objectives: [
    {
      max: 500,
      message: "培训目标不能超过500个字符",
      trigger: "blur"
    }
  ],
  schedule: [
    {
      max: 1000,
      message: "课程安排不能超过1000个字符",
      trigger: "blur"
    }
  ],
  materials: [
    {
      max: 500,
      message: "培训材料不能超过500个字符",
      trigger: "blur"
    }
  ],
  remark: [
    {
      max: 500,
      message: "备注不能超过500个字符",
      trigger: "blur"
    }
  ]
});

export {
  type FormItemProps,
  type FormProps,
  TrainingStatus,
  TrainingLevel,
  TrainingStatusText,
  TrainingLevelText,
  TrainingCategoryOptions,
  formRules
};